<template>
  <!-- 检查事项 -->
  <div class="dialog-container">
    <el-dialog
      title="更改发布人和责任人"
      :visible="dialogVisible"
      @open="initData"
      @close="closeDialog"
    >
      <el-form
        ref="form"
        class="dialog-form"
        :rules="rules"
        label-width="110px"
        size="mini"
      >
        <el-row>
          <el-col :span="12">
            <el-form-item label="发布人" prop="publisherId">
              <v-projectPersonnel
                ref="kll"
                @ch="ch1"
              />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="责任人" prop="responsibilityId">
              <v-projectPersonnel
                ref="kll"
                @ch="ch2"
              />
            </el-form-item>
          </el-col>
        </el-row>
      </el-form>
      <span slot="footer" class="dialog-footer">
        <el-button :loading="saveLoading" class="sure-btn" size="mini" type="primary" @click="handleSave">保存</el-button>
        <el-button size="mini" class="cancel-btn" @click="closeDialog">取消</el-button>
      </span>
    </el-dialog>

  </div>
</template>

<script>
import { batch } from '@/api/base/outlet'
import VProjectPersonnel from '@/components/filter/personnelFilter'
export default {
  name: 'BatchDialog',
  components: {
    VProjectPersonnel
  },
  props: {
    dialogVisible: {
      type: Boolean,
      default: false
    },
    batch: {
      type: Array,
      default: null
    }
  },
  data() {
    return {
      saveLoading: false,
      publisherId: null,
      responsibilityId: null,
      info: null,
      rules: {
        // examineResult: [{ required: true, message: '请选择违法行为判定', trigger: 'change' }]
      }
    }
  },
  created() {
  },
  methods: {
    initData() {

    },
    handleSave() {
      if (this.batch) {
        this.saveLoading = true
        const dataForm = []
        if (this.publisherId != null && this.responsibilityId != null) {
          this.batch.forEach(item => {
            dataForm.push({ id: item.id, publisherId: this.publisherId, responsibilityId: this.responsibilityId })
          })
        } else if (this.publisherId != null && this.responsibilityId == null) {
          this.batch.forEach(item => {
            dataForm.push({ id: item.id, publisherId: this.publisherId })
          })
        } else if (this.publisherId == null && this.responsibilityId != null) {
          this.batch.forEach(item => {
            dataForm.push({ id: item.id, responsibilityId: this.responsibilityId })
          })
        }
        batch(dataForm).then(() => {
          this.$message.success('成功')
          this.$emit('flushPage')
          this.$emit('closeDialog')
          this.clearData()
          this.saveLoading = false
        }).catch(() => {
          this.saveLoading = false
        })
      }
    },
    closeDialog() {
      this.$emit('closeDialog')
      this.clearData()
      this.$refs['form'].clearValidate()
    },
    clearData() {
      this.dataForm = []
      this.$refs.kll.clearData()// 清除v-projectPersonnel组键内容
    },
    ch1(id) { // 拿到v-projectPersonnel组键选择的人员id
      this.publisherId = id
    },
    ch2(id) { // 拿到v-projectPersonnel组键选择的人员id
      this.responsibilityId = id
    }
  }
}
</script>

<style lang="scss" scoped>

</style>
